Home > Java Programming > Variables and Loops > Questions and Answers
01. |
What happens when the following code is compiled and run. Select the one correct answer. for(int i = 2; i < 4; i++) for(int j = 2; j < 4; j++) assert i!=j : i; | |||||||||||
|
02. |
class A { A(String s) { } A() { } } 1. class B extends A { 2. B() { } 3. B(String s) { 4. super(s); 5. } 6. void test() { 7. // insert code here 8. } 9. } Which of the below code can be insert at line 7 to make clean compilation ? | |||||||||||
|
03. |
What is the output for the below code ? public class Test { public static void main(String... args) { int a =5 , b=6, c =7; System.out.println("Value is "+ b +c); System.out.println(a + b +c); System.out.println("String "+(b+c)); } } | |||||||||||
|
04. |
What will be the result of compiling and run the following code: public class Test {
public static void main(String... args) throws Exception { Integer i = 34; int l = 34; if(i.equals(l)){ System.out.println(true); }else{ System.out.println(false); } } } | |||||||||||
|
05. |
What is the output for the below code ? 1. public class Test {
2. static int i =5; 3. public static void main(String... args) { 4. System.out.println(i++); 5. System.out.println(i); 6. System.out.println(++i); 7. System.out.println(++i+i++); 8. 9. } 10. } | |||||||||||
|
06. |
What is the output for the below code ? 1. public class Test { 2. public static void main(String... args) { 3. Integer i = 34; 4. String str = (i<21)?"jan":(i<56)?"feb":"march"; 5. System.out.println(str); 6. } 7. } | |||||||||||
|
07. |
What is the output for the below code ? 1. public class Test { 2. public static void main(String[] args){ 3. byte i = 128; 4. System.out.println(i); 5. } 6. } | |||||||||||
|
08. |
What is the output for the below code ? 1. public class Test { 2. int i=8; 3. int j=9; 4. public static void main(String[] args){ 5. add(); 6. } 7. public static void add(){ 8. int k = i+j; 9. System.out.println(k); 10. } 11. } | |||||||||||
|
09. |
public class Loop { public static void main(String[] args){ for(int i=0;false;i++){ System.out.println("java"); } } } What will be output of above program? | |||||||||||
|
10. |
What will be output of following program? public class Datatype { public static void main(String[] args) { byte b=127; b++; b++; System.out.println(b); } } | |||||||||||
|